using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class LoaiPhongDAO:DataProvider
    {
        public DataTable LayBang()
        {
            string sql = "select Ma,Ten,DonGia from LoaiPhong where Xoa=FALSE";
            DataTable dt = DocBang(sql);
            return dt;
        }
        public DataTable TraCuuLoaiPhong(string tenlp)
        {
            string sql = "select * from LoaiPhong where Xoa=FALSE and Ten='"+tenlp+"' ";
            return DocBang(sql);
        }
        public void Them(LoaiPhongDTO lpdto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.KetNoi();
            string str = "Insert into LoaiPhong(Ten, DonGia) values (?, ?)";

            OleDbCommand cmd = new OleDbCommand(str, cn);

            cmd.Parameters.Add("@Ten", OleDbType.WChar);
            cmd.Parameters.Add("@DonGia", OleDbType.Integer);

            cmd.Parameters["@Ten"].Value = lpdto.Ten;
            cmd.Parameters["@DonGia"].Value = lpdto.DonGia;

            cmd.ExecuteNonQuery();

            cn.Close();
        }
        public void Sua(LoaiPhongDTO lpdto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = KetNoi();
            string sql = "Update LoaiPhong Set Ten = ? , DonGia = ?  Where Ma = ?";
            OleDbCommand cmd = new OleDbCommand(sql, cn);

            cmd.Parameters.Add("@Ten", OleDbType.WChar);
            cmd.Parameters.Add("@DonGia", OleDbType.Integer);
            cmd.Parameters.Add("@Ma", OleDbType.Integer);

            cmd.Parameters["@Ten"].Value = lpdto.Ten;
            cmd.Parameters["@DonGia"].Value = lpdto.DonGia;
            cmd.Parameters["@Ma"].Value = lpdto.Ma;

            cmd.ExecuteNonQuery();
            cn.Close();
        }
        public void Xoa(int malp)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = KetNoi();
            string sql = "Update LoaiPhong Set Xoa = ?  Where Ma = ?";
            OleDbCommand cmd = new OleDbCommand(sql, cn);

            cmd.Parameters.Add("@Xoa", OleDbType.Boolean);
            cmd.Parameters.Add("@Ma", OleDbType.Integer);

            cmd.Parameters["@Xoa"].Value = true;
            cmd.Parameters["@Ma"].Value = malp;

            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
